home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / OTHIRES.ZIP / hires.doc < prev    next >
Text File  |  1996-03-21  |  10KB  |  195 lines

  1.  
  2.                       - THE OUTLAW TRIAD DEMO-SERIES -
  3.  
  4. ────────────────────────────────■ PART IV ■───────────────────────────────────
  5.  
  6.                            Written by : Vulture/OT
  7.                            Code in    : Assembler
  8.                            Topic      : High resolution
  9.  
  10. ──────────────────────────────■ Introduction ■────────────────────────────────
  11.  
  12.  Welcome to the Outlaw Triad demo-series! In these series we will be talking
  13.  about programming demo-effects in either pascal or assembler. Theory behind
  14.  the effects shall be discussed while a full sourcecode is also provided.
  15.  In this fourth release we will discuss the basics of high resolution modes
  16.  like 640*480*16. We will make simple stringwriter for use in these modes.
  17.  A full sourcecode in assember is included. It's a part of the sourcecode of
  18.  a BBS intro coded for Magicware. The Outlaw Triad Italian HQ. Enjoy!
  19.  
  20. ─────────────────────────────────■ Theory ■───────────────────────────────────
  21.  
  22.  Ok, I will not waste much time explaining how a stringwriter works since
  23.  these routines are fairly easy to make. However, I will spend a few bytes
  24.  on it. I mean, this still is a trainer, right? ;-)
  25.  
  26.  To show some text on the screen, you will have to state the text you
  27.  want. What we want is a label representing the text to show. Like this:
  28.  
  29.  Label Text Byte
  30.       DB   '   the text you want to show   ',0
  31.  
  32.  The major advantage of doing it this way is the fact that you can change
  33.  the text very easily. Another way I've seen in some intro sourcecodes is
  34.  stating the numeric values of the text, or something like that. A rather
  35.  odd way of doing things, IMHO.
  36.  Anyway, the "0" at the end of the string means that the text has come to
  37.  an end there. We will take care of that in our stringwriter routine.
  38.  Ok, now how to we show this text? That's the main question here. First, we
  39.  need a font to work with. In most small intros, the fontdata is organised
  40.  in a lineair way. For example, you could scan a pcxfile from left to right,
  41.  top to bottom and save the bytes to a constant. Ok, you also need to know
  42.  the x,y size of the font. We need them for calculating the exact starting
  43.  position in the fontdata of the specific character we want to draw. Next
  44.  thing you need is the character order. An example:
  45.  
  46.  Label Order Byte
  47.       DB   'abcdefghijklmnopqrstuvwxyz!?.,()":+-'
  48.  
  49.  Let's take a look at an example of how to locate a character in the data.
  50.  I assume the data is organised in a lineair way like a stated above. Also,
  51.  let's say the x and y size are both 16. If we wanted to locate the letter
  52.  'g', we would add (6*16) to the offset (start) of the fontdata. Why? Take
  53.  a look: The letter 'g' is the seventh letter in the fontorder. We want to
  54.  locate the upperleft corner (!) of that letter. So, by adding (6*16) to the
  55.  offset we are exactly where we want to be! We have simply skipped the first
  56.  6 characters (that is, the first scanline of those characters). Ok, when we
  57.  have located that particular position, we can draw the char. You could do
  58.  something like this:
  59.  
  60.     - Go into a loop where you:
  61.       - Draw 16 pixels
  62.       - Update pointer to fontdata (remember: fontdata is lineair)
  63.       - Update vga position
  64.  
  65.  Do this 16 times (y was 16 here) and you're done. Ok, I don't want to waste
  66.  much more space explaining this so here are the steps you could take to show
  67.  some text:                                                ~~~~~
  68.  
  69.      1 - Load a character from the text
  70.      2 - Do appropiate action (in case of "0")
  71.      3 - Reset counter
  72.      4 - Go into a loop:
  73.        a - Load a character from order
  74.        b - Compare with the character from the text
  75.        c - If not the same, increase counter, back to A
  76.      5 - They were the same, now use the counter to find
  77.          the position of the character in the fontdata
  78.          (The way this is done depends on how the data is
  79.           organised. Check out the source to see what I mean)
  80.      6 - Draw the character
  81.      7 - Do next one
  82.  
  83.  Well, and that's it! You can use these steps in any resolution you want.
  84.  In our case, high resolution 640*480*16. Let's take a closer look at this
  85.  particular mode, shall we?
  86.  
  87.  Each byte in high resolution vgamemory represents 8 neighboring horizontal
  88.  pixels! In a byte are 8 bits, so each bit is 1 pixel on the screen! Quite
  89.  a difference compared to standard mode 13h where 1 byte represented one
  90.  pixel on the screen. Ok, since you are working with groups of 8 horizontal
  91.  pixels at a time, the logical screenwidth is now 80. Think about it! The
  92.  screenwidth in pixels is 640. Because 1 byte represents 8 horizontal pixels,
  93.  the logical screenwidth is 640/8=80. You use the logical screenwidth when
  94.  drawing a character on the screen.
  95.  When you write a byte to the screen, you can select the bits (pixels) you
  96.  want by writing the byte into the Bit Mask Register. This is index 08h of
  97.  the Graphic Controller. All enabled bits in this register will be written
  98.  to the screen and all not-enabled bits will not be written to the screen!
  99.  So, with this register you could write a PutPixel routine. Anyway, typical
  100.  code to write a byte (a pattern of 8 horizontal pixels) to the screen can
  101.  look something like:
  102.  
  103.      mov   dx,03ceh       ; Graphic Controller
  104.      mov   ah,ds:[si]     ; The byte to write (pointed to by ds:si)
  105.      mov   al,08h         ; Bit Mask Register
  106.      out   dx,ax
  107.      movsb                ; From data to vga (es:di points to vga)
  108.  
  109.  This is exactly what I did in the sourcecode. Note when using the Bit Mask
  110.  Register, all pixels you write to the vga will have the same color. If you
  111.  want them to have different colors you could use a PutPixel procedure in
  112.  which you set the color for the dot to write. Ok, you would like to have
  113.  a PutPixel routine for use in this mode, right? Well, I could give you one
  114.  but I won't. Instead, I will give you some hints on how to code your own.
  115.  
  116.      - Set color of dot
  117.      - Multiply Y with 80
  118.      - Divide X with 8
  119.      - Y=Y+X
  120.      - Set correct bit (using Bit Mask register => X and 7)
  121.      - Read dummy byte from vga (loading latches)
  122.      - Write byte to screen
  123.  
  124.  There you go! It shouldn't be hard to write a PutPixel routine now. If you
  125.  don't succeed, please mail me. I will give you my own routine instead.
  126.  
  127.  Ok, one more thing to discuss and that is setting the color for a dot. Like
  128.  I stated before, you should load the byte you want to write to the screen
  129.  into the Bit Mask Register before you write it to the screen. All enabled
  130.  bits will be written to the screen with the same data as presented in the
  131.  Set/Reset Register! With this, we can set the color of the dot we want to
  132.  write to the screen. The Set/Reset Register is 4 bits width so this leaves
  133.  us with a maximum number of 16 colors. Colorsetting code in assembler:
  134.  
  135.      mov     dx,3ceh           ; Graphic Controller address register port
  136.      mov     ax,0f01h          ; Index 01h  (enable set/reset register)
  137.      out     dx,ax             ; Enable all 4 bits to be altered
  138.      xor     al,al             ; Index 00h  (set/reset register)
  139.      mov     ah,cl             ; Color (0 to 15)
  140.      out     dx,ax             ; Set color
  141.  
  142.  There are 2 registers to be altered here. The Enable Set/Reset Register and
  143.  the Set/Reset Register. They are both 4 bits in width. If you enable a bit
  144.  in the Enable Set/Reset Register, the corresponding bit in the Set/Reset
  145.  Register can be altered. And, when you disable a bit in the Enable Set/Reset
  146.  Register, the corresponding bit in the Set/Reset Register can't be altered.
  147.  So, we set all (4) bits in the Enable Set/Reset Register to 1. This way, all
  148.  bits (4) of the Set/Reset Register may be altered. Then, we load the color
  149.  into the Set/Reset Register. Any byte (bits) that is written to the screen
  150.  will have this color. Why don't you make a sample program to test this code?
  151.  It should work just fine. (note: I used this code in my own PutPixel proc).
  152.  
  153.  One advantage of these high resolution modes is that you need just a few
  154.  bytes to represent an entire character. Like in this example source, you
  155.  only need 2*18=36 bytes. If you want to show a character this size in plain
  156.  mode 13h, you would need 16*18=288 bytes. Quite a difference, eh?
  157.  (note: this doesn't have to be true. When using a single color font, you
  158.  can also store the pixels in bits in mode 13h).
  159.  A disadvantage of high resolution mode is that you only have 16 colors to
  160.  you disposal.
  161.  
  162.  Now go and take a look at the sourcecode provided in this package. It is
  163.  fully documented so there shouldn't be any problems. If you have troubles
  164.  after all, e-mail me. I like to hear from you!
  165.  
  166.  Ok, this is all for now. Happy coding!
  167.  
  168.        - Vulture / Outlaw Triad -
  169.  
  170. ───────────────────────────────■ Distro Sites ■───────────────────────────────
  171.  
  172.  Call our distros to get all our releases.
  173.  
  174.   BlueNose    World HQ          +31 (0)345-619401
  175.   FireHouse   Distrosite        +31 (0)528-274176
  176.   The Force   Distrosite        +31 (0)36-5346967    More distros wanted!
  177.   MagicWare   Italian HQ        +39  6-52355532
  178.   ShockWave   South African HQ  +27 (011)888-6345
  179.  
  180. ──────────────────────────────────■ Contact ■─────────────────────────────────
  181.  
  182.  Want to contact Outlaw Triad for some reason? You can reach us at our
  183.  distrosites in Holland. Or if you have e-mail access, mail us:
  184.  
  185.    Vulture  (coder/pr)     comma400@tem.nhl.nl
  186.  
  187.  Our internet homepage:
  188.  
  189.    http://www.tem.nhl.nl/~comma400/vulture.html
  190.  
  191.  These internet adresses should be valid at least till june 1996.
  192.  
  193. ──────────────────────────────────────────────────────────────────────────────
  194.  
  195.                   Quote:  Does killing time hurt eternity?